//
//  UIView+textFieldShock.m
//  输入框shank
//
//  Created by 袁庆秋 on 15/5/5.
//  Copyright (c) 2015年 袁庆秋. All rights reserved.
//

#import "UIView+textFieldShock.h"

@implementation UIView (textFieldShock)

- (void)textFieldShock
{
    CALayer *lbl = [self layer]; // 获取view的CALayer
    CGPoint posLbl = [lbl position]; // 获取CALayer的center
    CGPoint y = CGPointMake(posLbl.x-10, posLbl.y); // 向左抖动距离
    CGPoint x = CGPointMake(posLbl.x+10, posLbl.y); // 向右抖动距离
    CABasicAnimation * animation = [CABasicAnimation animationWithKeyPath:@"position"]; // 声明animation动画完成后返回到原始位置
    [animation setTimingFunction:[CAMediaTimingFunction
                                  functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
    // 设置动画速度,此处为渐进渐出,缓慢进入,中间加速,然后减速到达目的地
    [animation setFromValue:[NSValue valueWithCGPoint:x]]; // 设置动画开始点
    [animation setToValue:[NSValue valueWithCGPoint:y]]; // 设置动画结束点
    [animation setAutoreverses:YES];
    [animation setDuration:0.08]; // 时间间隔
    [animation setRepeatCount:3]; // 抖动次数
    [lbl addAnimation:animation forKey:nil];//添加动画效果
}

@end
